//context 父子组件传值
//reducer 管理store

import React,{createContext , useReducer} from 'react';

//context 定义
export const ColorContext = createContext({})

//action
export const UPDATE_COLOR = " "

//reducer
const reducer =(state,action)=>{
    switch(action.type){
        case UPDATE_COLOR:
            return action.color
        default:
            return state    
    }
}



//共享
export const Color = props=>{
    //使用useRducer
    const [color,dispatch] = useReducer(reducer,'blue')
    return(
        <ColorContext.Provider value={{color,dispatch}}>
            {props.children} 
        </ColorContext.Provider>
    )
}



//props.children 获取color组件中间的内容就是获取showArea和 buttons组件